#include <iostream>
using std::cout;
using std::endl;
//内存布局
//栈区：局部变量
//再次加入全局静态区
int globalNumber = 20;
static int staticNumber = 50;
//常量
const int constNumber = 100;
void test(){
    int localNumber = 10;
    int localNumber2 = 10;
    //int * localPointer;
    cout << &localNumber << endl;
    cout << &localNumber2 << endl;
    //堆区
    //heap本身是一个栈变量，它指向的是堆区
    int * heap = new int();
    cout << heap << endl;//打印的是指针变量所指向的堆区的地址
    cout << &heap << endl;//打印的是指针变量本身的地址
    delete heap;
    heap = nullptr;
    //查看全局静态区的地址
    cout << &globalNumber << endl;
    cout << &staticNumber << endl;
    cout << "=====================" << endl;
    //常量
    //本质依然是一个栈变量
    const int constNumber2 = 200;
    const char * pstr = "hello";
    cout << &constNumber << endl;
    cout << &constNumber2 << endl;
    cout << (void *)pstr << endl;
    cout << &pstr << endl;
    //main函数便是位于程序代码区
    cout << (void *)&test << endl;
}

int main()
{
    test();
    return 0;
}

